package com.coco.group.config.zkconfig;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/8/5 14:51
 */
@Slf4j
@Configuration
public class ZookeeperConfig {

    /**
     * 读取服务地址
     */
    @Value("${zk.url}")
    private String zkAddress;

    /**
     * 注入Curator客户端
     * @return
     */
    @Bean
    public CuratorFramework getCuratorFramework(){
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(zkAddress,retryPolicy);
        client.start();
        return client;
    }




}
